package com.qf.boot2302.filter;

import com.qf.boot2302.mapper.StudentMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//@WebFilter("/hi")
@Slf4j
public class CheckUserNameFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        System.out.println("==============CheckUserNameFilter 开始工作===============");
        // 让请求就此打住
        String username = request.getParameter("username");
        if (username==null){
            log.info("必传参数username为null了");
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().println("必传参数username为空");
        }else {
            // 放行该请求
            chain.doFilter(request,response);
            System.out.println("==============CheckUserNameFilter 结束工作===============");

        }

    }
}
